package dd爱旋转;

import java.io.*;
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    static int N = 1010, n;
    static int[][] arr = new int[N][N];

    public static void main(String[] args) throws IOException {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
      n = Integer.parseInt(in.readLine());
        for (int i = 0; i < n; i++) {
            String[] s= in.readLine().split(" ");
            for (int j = 0; j < n; j++) {
                arr[i][j] = Integer.parseInt(s[j]);
            }
        }
        int q = Integer.parseInt(in.readLine());
        int x1 = 0,x2 = 0;
        while (q-->0){
            int x = Integer.parseInt(in.readLine());
            if(x == 1){
                x1++;
            }
            x2++;
        }
        if(x1%2 == 1){
            fun1();
        }
        if(x2%2 == 1){
            fun2();
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                out.write(arr[i][j]+" ");
            }
            out.newLine();
        }
        out.flush();;
    }
    private static void fun2(){
        for (int i = 0; i < n/2 ; i++) {
            for (int j = 0; j < n; j++) {
                swap(i,j,n-1-i,j);
            }
        }
    }

    private static void fun1(){
        for (int i = 0; i < n ; i++) {
            for (int j = 0; j < n/2; j++) {
                swap(i,j,i,n-1-j);
            }
        }
    }
    private static void swap(int x1,int y1,int x2,int y2){
        int t = arr[x1][y1];
        arr[x1][y1] = arr[x2][y2];
        arr[x2][y2] = t;
    }
}